package com.chebaohui.iqs.service.impl.deal.taiping.ev;

import com.alibaba.fastjson.JSONObject;
import com.chebaohui.iqs.config.CompanyValue;
import com.chebaohui.iqs.service.impl.deal.taiping.DirectTp;
import com.chebaohui.iqs.service.impl.deal.taiping.PublicNew;
import com.chebaohui.iqs.service.impl.deal.taiping.RequestHead;
import com.chebaohui.iqs.service.impl.deal.taiping.ResTaiPing;

/**
 * V04-支付登记
 * 
 * @author xielonghai
 * @version 2016-07-08
 */
public class V04Request {

	/**
	 * 支付登记接口方法
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param param
	 *            请求参数json
	 * @return
	 */
	public static ResTaiPing requestV04(String session, JSONObject param) {
		String value = CompanyValue.TAIPING + ":主接口-支付登记";
		String[] key = { "basePay" // 支付信息（basePay）
		};
		return DirectTp.request(value, PublicNew.REQUEST_URL + "/paymentRegister", getRequest(session, param), key);
	}

	/**
	 * V04-支付登记------请求参数
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param param
	 *            请求参数json
	 * @return
	 */
	public static String getRequest(String session, JSONObject param) {
		JSONObject head = RequestHead.getHead(session);
		String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
		request = request + "\n" + "<request>";
		request = request + "\n" + "<head>";

		request = request + "\n\t" + "<msgId>" + head.getString("msgId") + "</msgId>";
		request = request + "\n\t" + "<timeStamp>" + head.getString("timeStamp") + "</timeStamp>";
		request = request + "\n\t" + "<session>" + head.getString("session") + "</session>";
		request = request + "\n\t" + "<userCode>" + head.getString("userCode") + "</userCode>";
		request = request + "\n\t" + "<clientName>" + head.getString("clientName") + "</clientName>";

		request = request + "\n" + "</head>";

		request = request + "\n" + "<body>";
		request = request + "\n" + "<payment>";
		/** 前端回调地址--支付成功时，跳入这个界面 **/
		request = request + "\n\t" + "<partnerUrl>" + param.getString("partnerUrl") + "</partnerUrl>";
		/**
		 * 支付请求来源
		 * 
		 * 电脑PC支付：web
		 * 
		 * 微信移动端可支持多支付方式选择, “微信支付，支付宝扫码，快钱”:wapPay1
		 * 
		 * 非微信移动端可支持多支付方式选择, “移动支付宝，微信扫码，快钱”: wapPay2
		 * 
		 **/
		request = request + "\n\t" + "<requestSource>" + param.getString("requestSource") + "</requestSource>";
		// request = request + "\n\t" + "<risk>";
		// request = request + "\n\t\t" + "<riskCode>" +
		// param.getString("proposalNo") + "</riskCode>";//
		// request = request + "\n\t\t" + "<proposalNo>" +
		// param.getString("proposalNo") + "</proposalNo>";//
		// request = request + "\n\t" + "</risk>";
		request = request + "\n" + "</payment>";

		request = request + "\n" + "<order>";
		request = request + "\n\t" + "<orderNo>" + param.getString("orderNo") + "</orderNo>";// 业务单号
		request = request + "\n" + "</order>";

		request = request + "\n" + "</body>";

		request = request + "\n" + "</request>";
		return request;
	}
}
